﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace SharpDiary.Reminder
{

    public partial class ReminderDateTimePicker : UserControl
    {
        /// <summary>
        /// 提醒类型。
        /// </summary>
        public ReminderType ReminderType
        {
            get { return (chbDaily.Checked ? ReminderType.DailyTime : ReminderType.DateAndTime); }
            set
            {
                UpdateUI(value);
            }
        }

        private void UpdateUI(ReminderType reminderType)
        {
            switch (reminderType)
            {
                case ReminderType.DailyTime:
                    {
                        chbDaily.Checked = true;

                        dtpDate.Hide();
                        dtpTime.Location = new Point(0, 1);
                        chbDaily.Location = new Point(dtpTime.Left + dtpTime.Width + 5, dtpTime.Top);

                        break;
                    }
                case ReminderType.DateAndTime:
                    {
                        chbDaily.Checked = false;

                        dtpDate.Location = new Point(0, 1);
                        dtpDate.Show();
                        dtpTime.Location = new Point(dtpDate.Left + dtpDate.Width + 5, dtpDate.Top);
                        chbDaily.Location = new Point(dtpTime.Left + dtpTime.Width + 5, dtpTime.Top);

                        break;
                    }
            }
        }

        public DateTime Value
        {
            get
            {
                return new DateTime(dtpDate.Value.Year, dtpDate.Value.Month, dtpDate.Value.Day,
                    dtpTime.Value.Hour, dtpTime.Value.Minute, dtpTime.Value.Second);
            }
            set
            {
                dtpDate.Value = value.Date;
                dtpTime.Value = value;
            }
        }

        public ReminderDateTimePicker()
        {
            InitializeComponent();

            ResizeRedraw = true;
            DoubleBuffered = true;
        }

        private void chbDaily_CheckedChanged(object sender, EventArgs e)
        {
            UpdateUI(chbDaily.Checked ? ReminderType.DailyTime : ReminderType.DateAndTime);
        }
    }
}
